﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.Admin
{
    [Access("257002,257003,257004")]
    public partial class Manage : WebFactory.PageBase
    {
        private readonly AdminManage _myBll = PolicyInjection.Create<AdminManage>();


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(IsPostBack))
            {
                BindList(1);
            }
        }

        private void BindList(int pageNo)
        {
            var pp = new PagingParam {PageSize = this.PageNavigation1.PageSize, PageNo = pageNo};
            var list = new UserManage().BindList(true, pp);
            this.GV_List.DataSource = list;
            this.GV_List.DataBind();

            this.PageNavigation1.RecordCount = pp.RecordCount;
        }

        protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var model = new User
            {
                Id = Convert.ToInt32(this.GV_List.DataKeys[e.RowIndex].Value),
                UserName = this.GV_List.Rows[e.RowIndex].Cells[1].Text
            };

            var res = this._myBll.Delete(model);
            if (res.Errors.Length > 0)
            {
                MsgBox.Message(res.Errors, this.UpdatePanel2);
            }
            else
            {
                MsgBox.Message("删除成功!", this.UpdatePanel2);
                BindList(1);
            }
        }

        protected void PageNavigation1_PageChanging(object src, WebControls.PageChangingEventArgs e)
        {
            BindList(e.NewPageIndex);
        }

        protected void GV_List_RowEditing(object sender, GridViewEditEventArgs e)
        {
        }
    }
}